#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require



#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"
#include "../../../../core/shader_mesh.h"


layout(push_constant, scalar) uniform DRAWPROP_push_constants {
	S_ConstPush_Mesh_Point const_push;
};

layout(std140, set = 0, column_major, binding = DEF_BINDING_PROJECT) uniform Buf0 {
	mat4 mat_ProjecView[4];
};

layout(std430, set = 1, scalar, column_major, binding = DEF_binding_L1_3D_Tranform) readonly buffer Buf1 {
	mat4 mat_Model[];
};


layout(location = 0) in vec3 inPos;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec3 inUV_Color;



out gl_PerVertex {
	vec4 gl_Position;
	float gl_PointSize;
};

layout(location = 0) out vec4 outColor;
layout(location = 1) out uint outShaderType;


vec3 pos[4] = {vec3(10.0, -10.0, 10), vec3(-100.0, 10.0,-2), vec3(10.0, 100.0,0), vec3(100.0, 100.0,0)};

void main(void){
	mat4 bonesMat_som = mat_Model[const_push.m_Offset_Tranform];

	vec4 p = vec4(inPos, 1);
	
	outShaderType = const_push.m_Ob_ShaderType & 0xff;
	switch(outShaderType) {
		case DEF_3DShaderType_PerObCirclePoint :
		case DEF_3DShaderType_PerObColor : {
			outColor = f_glsl_buildColor(const_push.m_Ob_Color);
			break;
		}
		default:{
			outColor = f_glsl_buildColor(floatBitsToUint(inUV_Color.z));
		}
	}
	
	
	gl_PointSize = const_push.m_PointSize;
	gl_Position = (mat_ProjecView[DEF_Camera_Matrix_PV]) * bonesMat_som * p;
	
	vec4 ndcpos = gl_Position / gl_Position.w;
	ndcpos.xy += mat_ProjecView[DEF_Camera_Matrix_Porj][0].xy;
	gl_Position = ndcpos * gl_Position.w;
	
}


